*** Robustness table: sample of neighbouring municipalities ***

** Preamble **

clear all
set more off

local path_input  "C:/Users/$user/Dropbox/$project/master/output/data"
local path_output "C:/Users/$user/Dropbox/$project/master/output/tables"


* Note: local directory is the output folder 
cd "`path_output'"

					** Loading the input file **


use `path_input'/dataset_final_may20, clear

estimates clear

xtset codigo_ibge turno

local baseline_controls "pop1991 years_sch1991 renda1991 sh_tv1991 sh_agua1991 sh_elect1991 sh_rural"
local CGB_FEs			"pct_sh_tv1991 pct_sh_rural pct_renda1991"


/*generating percentiles*/
foreach var in `baseline_controls' {
xtile pct_`var'=  `var', n(10)
replace pct_`var'=0 if turno==2
}

/*generating pscores*/
encode uf, gen(UF)
psmatch2 Globo T1* if turno==1,  noreplace neighbor(1)
egen ppp=mean(_pscore), by(codigo)
gen pscore=1
replace pscore=ppp/(1-ppp) if Globo==0

label var treatment "Globo"
label var treatment1 "Globo and Others"
label var treatment2 "Globo Only"

foreach v of varlist * {

	label variable `v' `"\hspace{0.1cm} `: variable label `v''"'
	
}


drop _merge
merge 1:1 codigo_ibge turno using `path_input'/eleicoes1994.dta
drop _merge 

keep if esquerda!=.

											** Table: Paclebo with gubernatorial elections **

/*
The sample is restricted for the states of Acre, Amapá, Bahia, Distrito Federal, Espírito Santo, Goiás, Maranhão, Minas Gerais, Paraná, Paraíba, Rio de Janeiro, Rondônia, Roraima, Rio Grande do Sul, Santa Catarina, Sergipe, São Paulo, which held two rounds of gubernatorial elections in 1994. All specifications control for municipality fixed effects, time fixed effects. Untreated units are weighted by inverse propensity scores to create a control group with similar pretreatment characteristics (Abadie, 2005). Panel A reports estimates of falsification tests, estimating the effect of Globo's edited coverage on the 1994 Gubernatorial elections.   To account for the fact that we use vote shares from different gubernatorial elections, we control for first-round vote-shares interacted with state-time fixed effects in the regressions.  Panel B reports estimates of Globo' edited coverage on the left- and right-wing candidates second round' vote shares in the 1989 presidential elections for this particular subsample. Panel C reports estimates of Globo' edited coverage on Lula and Collor's second round' vote shares in the 1989 presidential elections for this particular subsample and includes first-round vote shares interacted with time fixed effects. In panels A and B, columns (1) and (2), respectively, report baseline estimates on the left- and right-wing parties' vote share as the dependent variables. Panel C repeats A and B's structure but uses Lula's and Collor's vote share as the dependent variables.  Heteroskedasticity-adjusted standard errors clustered at the municipality level are reported in brackets. Significantly different from zero at $99\% (***)$, $95\% (**)$, and $90\% (*)$ confidence level.
*/

local legend "The sample is restricted for the states of Acre, Amapá, Bahia, Distrito Federal, Espírito Santo, Goiás, Maranhão, Minas Gerais, Paraná, Paraíba, Rio de Janeiro, Rondônia, Roraima, Rio Grande do Sul, Santa Catarina, Sergipe, São Paulo, which held two rounds of gubernatorial elections in 1994. All specifications control for municipality fixed effects, time fixed effects. Untreated units are weighted by inverse propensity scores to create a control group with similar pretreatment characteristics (Abadie, 2005). Panel A reports estimates of falsification tests, estimating the effect of Globo's edited coverage on the 1994 Gubernatorial elections.   To account for the fact that we use vote shares from different gubernatorial elections, we control for first-round vote-shares interacted with state-time fixed effects in the regressions.  Panel B reports estimates of Globo' edited coverage on the left- and right-wing candidates second round' vote shares in the 1989 presidential elections for this particular subsample. Panel C reports estimates of Globo' edited coverage on Lula and Collor's second round' vote shares in the 1989 presidential elections for this particular subsample and includes first-round vote shares interacted with time fixed effects. In panels A and B, columns (1) and (2), respectively, report baseline estimates on the left- and right-wing parties' vote share as the dependent variables. Panel C repeats A and B's structure but uses Lula's and Collor's vote share as the dependent variables.  Heteroskedasticity-adjusted standard errors clustered at the municipality level are reported in brackets. Significantly different from zero at $99\% (***)$, $95\% (**)$, and $90\% (*)$ confidence level."
						
											** panel A **
											
tab uf, gen(uf_)
forvalues i=1/17{
	foreach var in PDT_ PT_ PTB_ PMDB_ PRONA_ PRN_ PFL_ PSB_ PMN_ PP_ PPR_ PSC_ PSD_ PSDB_ BRANCOS_ NULOS_{
	
	gen `var'uf_`i'=`var'*uf_`i'
	replace `var'uf_`i'=0 if `var'uf_`i'==.
	
	}
}
											

												** Panel A **
												
eststo: xi: reghdfe esquerda treatment turno PDT_uf_1-PSDB_uf_17 	[pw=pscore], vce(cluster codigo_ibge) a(codigo_ibge)
estadd local PartiesControl "Yes"

eststo: xi: reghdfe direita  treatment turno PDT_uf_1-PSDB_uf_17 	[pw=pscore], vce(cluster codigo_ibge) a(codigo_ibge)
estadd local PartiesControl "Yes"


												** panel B **
											
											
eststo: xi: reghdfe sh_Tesquerda treatment turno 					[pw=pscore], vce(cluster codigo_ibge) a(codigo_ibge)
estadd local PartiesControl "No"

eststo: xi: reghdfe sh_Tdireita  treatment turno 					[pw=pscore], vce(cluster codigo_ibge) a(codigo_ibge)
estadd local PartiesControl "No"


												** panel C **

eststo: xi: reghdfe sh_Tpt_  treatment turno sh_Tpsp_-sh_Tpsdb_ 	[pw=pscore], vce(cluster codigo_ibge) a(codigo_ibge)
estadd local PartiesControl "Yes"

eststo: xi: reghdfe sh_Tprn_ treatment turno sh_Tpsp_-sh_Tpsdb_ 	[pw=pscore], vce(cluster codigo_ibge) a(codigo_ibge)
estadd local PartiesControl "Yes"


										*** Producing tables ***

						** panel A **

esttab est1 est2 using Table_falsification_panel_A.tex, ///
keep(treatment) ///
order(treatment) ///
stat(N r2 PartiesControl, fmt(0 2 0) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{S}{@}" "\multicolumn{1}{c}{@}") ///
label("Observations" "R-squared" "Electoral controls * Round")) ///
star(* 0.10 ** 0.05 *** 0.01) ///
nomtitles  ///
r2 b(3) replace  se(3) brac compress nonotes label  nogaps staraux ///
nonotes addnotes("\begin{minipage}{.75\linewidth} \footnotesize \smallskip \textbf{Note:} `legend' \end{minipage}" )

						** panel B **

esttab est3 est4 using Table_falsification_panel_B.tex, ///
keep(treatment) ///
order(treatment) ///
stat(N r2 PartiesControl, fmt(0 2 0) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{S}{@}" "\multicolumn{1}{c}{@}") ///
label("Observations" "R-squared" "Electoral controls * Round")) ///
star(* 0.10 ** 0.05 *** 0.01) ///
nomtitles  ///
r2 b(3) replace  se(3) brac compress nonotes label  nogaps staraux ///
nonotes addnotes("\begin{minipage}{.65\linewidth} \footnotesize \smallskip \textbf{Note:} `legend' \end{minipage}" )

						** panel C **

esttab est5 est6 using Table_falsification_panel_C.tex, ///
keep(treatment) ///
order(treatment) ///
stat(N r2 PartiesControl, fmt(0 2 0) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{S}{@}" "\multicolumn{1}{c}{@}") ///
label("Observations" "R-squared" "Electoral controls * Round")) ///
star(* 0.10 ** 0.05 *** 0.01) ///
nomtitles  ///
r2 b(3) replace  se(3) brac compress nonotes label  nogaps staraux ///
nonotes addnotes("\begin{minipage}{.65\linewidth} \footnotesize \smallskip \textbf{Note:} `legend' \end{minipage}" )


include "https://raw.githubusercontent.com/steveofconnell/PanelCombine/master/PanelCombine.do"

panelcombine, use(Table_falsification_panel_A.tex Table_falsification_panel_B.tex Table_falsification_panel_C.tex) ///
paneltitles("Gubernatorial election (1994)" "Presidential elections (1989)" "Presidential elections (1989)") columncount(3) save(placebo_governo1994.tex) cleanup
